//
//  PublicGetDetailDate.m
//  Yanwei
//
//  Created by Seven-Augus on 2017/5/15.
//  Copyright © 2017年 DCloud. All rights reserved.
//

#import "PublicGetDetailDate.h"

@implementation PublicGetDetailDate

#pragma mark - 获取当前年月日
+ (NSDictionary *)getNowDate {
    
    NSDate *date = [NSDate date];
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"yyyy"];
    NSInteger currentYear = [[formatter stringFromDate:date] integerValue];
    
    [formatter setDateFormat:@"MM"];
    NSInteger currentMonth = [[formatter stringFromDate:date]integerValue];
    
    [formatter setDateFormat:@"dd"];
    NSInteger currentDay = [[formatter stringFromDate:date] integerValue];
    
    NSDictionary *nowDateDic = @{@"nowYear":[NSString stringWithFormat:@"%ld", currentYear], @"nowMonth":[NSString stringWithFormat:@"%ld", currentMonth], @"nowDay":[NSString stringWithFormat:@"%ld", currentDay]};
//    NSLog(@"currentDate = %@ ,year = %ld ,month = %ld, day = %ld", date, currentYear, currentMonth, currentDay);
    
    return nowDateDic;
}

#pragma mark - 获取某年某月的日
+ (NSMutableArray *)howManyDaysInThisYear:(NSInteger)year withMonth:(NSInteger)month {
    
    NSMutableArray *daysNumArray = [[NSMutableArray alloc] init];
    NSInteger daysNum = 29;
    
    if ((month == 1) || (month == 3) || (month == 5) || (month == 7) || (month == 8) || (month == 10) || (month == 12)) {
        daysNum = 31;
        for (int i = 0; i < daysNum; i ++) {
            [daysNumArray addObject:[NSString stringWithFormat:@"%d", i +1]];
        }
        return daysNumArray;
    }
    
    if ((month == 4) || (month == 6) || (month == 9) || (month == 11)) {
        daysNum = 30;
        for (int i = 0; i < daysNum; i ++) {
            [daysNumArray addObject:[NSString stringWithFormat:@"%d", i +1]];
        }
        return daysNumArray;
    }
    
    if ((year % 4 == 1) || (year % 4 == 2) || (year % 4 == 3)) {
        daysNum = 28;
        for (int i = 0; i < daysNum; i ++) {
            [daysNumArray addObject:[NSString stringWithFormat:@"%d", i +1]];
        }
        return daysNumArray;
    }
    
    if (year % 400 == 0) {
        daysNum = 29;
        for (int i = 0; i < daysNum; i ++) {
            [daysNumArray addObject:[NSString stringWithFormat:@"%d", i +1]];
        }
        return daysNumArray;
    }
    
    if (year % 100 == 0) {
        daysNum = 28;
        for (int i = 0; i < daysNum; i ++) {
            [daysNumArray addObject:[NSString stringWithFormat:@"%d", i +1]];
        }
        return daysNumArray;
    }
    
    for (int i = 0; i < daysNum; i ++) {
        [daysNumArray addObject:[NSString stringWithFormat:@"%d", i +1]];
    }
    return daysNumArray;
}

@end
